package com.smile.frame.websocket.netty.service.util;

import com.smile.frame.websocket.netty.service.dto.ClientInfoDTO;
import io.netty.channel.Channel;

/**
 * 客户端通道绑定
 *
 * @author LGC
 */
public class ChannelAttrUtil {

    /**
     * 将client绑定至管道中
     */
    public static void bindClient(Channel channel, ClientInfoDTO clientInfo) {
        channel.attr(ChannelAttributes.CLIENT).set(clientInfo);
    }

    /**
     * 通道中获取client
     */
    public static ClientInfoDTO getClient(Channel channel) {
        return channel.attr(ChannelAttributes.CLIENT).get();
    }


    /**
     * client解除绑定在管道中
     */
    public static void unbindClient(Channel channel) {
        channel.attr(ChannelAttributes.CLIENT).set(null);
    }

    /**
     * 判断通道中是否存在client，存在则已经登录
     */
    public static boolean channelHasClient(Channel channel) {
        return channel.hasAttr(ChannelAttributes.CLIENT);
    }


}
